package com.hdu.joinInMemory.repository;

import com.hdu.joinInMemory.entity.DO.User;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

@Repository
public class UserRepository {

    private static final List<User> USERS = new ArrayList<>();
    static {
        for (int i = 0; i < 100; i++) {
            long j = i + 1;
            USERS.add(User.builder().id(j).name("qyh--" + j).build());
        }
    }

    public List<User> findUserById(List<Long> userId) {
       return USERS.stream().filter(user -> userId.contains(user.getId())).collect(Collectors.toList());
    }

    public User findUserById(Long userId) {
        return USERS.stream().filter(user -> user.getId().equals(userId)).findFirst().orElse(null);
    }
}
